/**
 * 
 */
package com.iwords.service.object;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.Transient;

/**
 * @author BOLIN.HBC
 * @time 2011-3-6
 * @description USER-DO
 */
@Entity
@Table(name = "users")
public class UserEntity implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long userid;
    private String username;
    private String password;
    private Long currentlib;
    private String nickname;
    private String email;
    private String phone;
    private String qq;
    private String gender;
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date birthday;
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date createtime;
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date updatetime;
    @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY, mappedBy = "user")
    private List<UserSysConfigEntity> userSysConfigs = new ArrayList<UserSysConfigEntity>();
    @OneToOne(cascade = {CascadeType.ALL}, mappedBy = "user")
    private UserVacation userVacation;
    @Transient
    private Long messageid;
    @Transient
    private String message;
    @Transient
    private Integer type;
    /**根据推广ID，查到Teacherid，在学生付款的时候插入*/
    private Long teacherid;
    /**最近学习时间*/
    @Transient
    private Date lastLearningTime;

    public Date getLastLearningTime() {
        return lastLearningTime;
    }

    public void setLastLearningTime(Date lastLearningTime) {
        this.lastLearningTime = lastLearningTime;
    }
    
    
    
    public Long getTeacherid() {
        return teacherid;
    }

    public void setTeacherid(Long teacherid) {
        this.teacherid = teacherid;
    }

    /**
     * @return the userid
     */
    public Long getUserid() {
        return userid;
    }

    /**
     * @return the type
     */
    public Integer getType() {
        return type;
    }

    /**
     * @param type the type to set 
     */
    public void setType(Integer type) {
        this.type = type;
    }

    /**
     * @return the messageid
     */
    public Long getMessageid() {
        return messageid;
    }

    /**
     * @param messageid the messageid to set 
     */
    public void setMessageid(Long messageid) {
        this.messageid = messageid;
    }

    /**
     * @return the message
     */
    public String getMessage() {
        return message;
    }

    /**
     * @param message the message to set 
     */
    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * @param userid
     *            the userid to set
     */
    public void setUserid(Long userid) {
        this.userid = userid;
    }

    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }

    /**
     * @param username
     *            the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password
     *            the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the nickname
     */
    public String getNickname() {
        return nickname;
    }

    /**
     * @param nickname
     *            the nickname to set
     */
    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email
     *            the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return the phone
     */
    public String getPhone() {
        return phone;
    }

    /**
     * @param phone
     *            the phone to set
     */
    public void setPhone(String phone) {
        this.phone = phone;
    }

    /**
     * @return the qq
     */
    public String getQq() {
        return qq;
    }

    /**
     * @param qq
     *            the qq to set
     */
    public void setQq(String qq) {
        this.qq = qq;
    }

    /**
     * @return the gender
     */
    public String getGender() {
        return gender;
    }

    /**
     * @param gender
     *            the gender to set
     */
    public void setGender(String gender) {
        this.gender = gender;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Long getCurrentlib() {
        return currentlib;
    }

    public void setCurrentlib(Long currentlib) {
        this.currentlib = currentlib;
    }

    public Date getCreatetime() {
        return createtime;
    }

    public void setCreatetime(Date createtime) {
        this.createtime = createtime;
    }

    public Date getUpdatetime() {
        return updatetime;
    }

    public void setUpdatetime(Date updatetime) {
        this.updatetime = updatetime;
    }

    public List<UserSysConfigEntity> getUserSysConfigs() {
        return userSysConfigs;
    }

    public void setUserSysConfigs(List<UserSysConfigEntity> userSysConfigs) {
        this.userSysConfigs = userSysConfigs;
    }

    public UserVacation getUserVacation() {
        return userVacation;
    }

    public void setUserVacation(UserVacation userVacation) {
        this.userVacation = userVacation;
    }

    /**
     * 添加用户系统配置
     * @param userSysConfigEntity
     */
    public void addSysConfig(UserSysConfigEntity userSysConfigEntity) {
        if (!this.userSysConfigs.contains(userSysConfigEntity)) {
            this.userSysConfigs.add(userSysConfigEntity);
        }
    }

    /**
     * 删除用户系统配置
     * @param userSysConfigEntity
     */
    public void removeSysConfig(UserSysConfigEntity userSysConfigEntity) {
        if (this.userSysConfigs.contains(userSysConfigEntity)) {

            this.userSysConfigs.remove(userSysConfigEntity);
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final UserEntity other = (UserEntity) obj;
        if (this.userid != other.userid && (this.userid == null || !this.userid.equals(other.userid))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 71 * hash + (this.userid != null ? this.userid.hashCode() : 0);
        return hash;
    }
    
}
